package com.rocching.easychat.core;

import androidx.annotation.IdRes;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;

import com.rocching.easychat.util.ClickUtil;

/**
 * 避免在1.5秒内触发多次点击
 *
 * @author chengqian
 * Created on 2018/10/12
 */
public abstract class ViewClickListener implements OnClickListener, AdapterView.OnItemClickListener {
    @Override
    public void onClick(View v) {
        if (ClickUtil.isQuicklyClick(v, getMinClickDuration())) {
            return;
        }
        onDClick(v);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        if (ClickUtil.isQuicklyClick(view, getMinClickDuration())) {
            return;
        }
        onDItemClick(adapterView, view, i, l);
    }

    /**
     * 点击回调
     *
     * @param v 被点击的View对象
     */
    public void onDClick(View v) {

    }

    public void onDItemClick(AdapterView<?> adapterView, View view, int i, long l) {

    }

    /**
     * 最小的点击时间间隔：毫秒值
     *
     * @return /
     */
    public int getMinClickDuration() {
        return 1000;
    }
}
